#include "GLUTGUIWrapper.h"
#include <GLUT/GLUT.h>
#include <iostream>
#include "GullEngine.h"

using namespace gull::core;



extern "C"
void displayFunc()
{
	theGullEngine->mainLoop();
}

extern "C"
void reshapeFunc(int w, int h)
{
	theGullEngine->reshape(w,h);
}

GLUTGUIWrapper::GLUTGUIWrapper():m_windowIdentifier(0)
{
	
}

int 
GLUTGUIWrapper::initGUIAPI() const
{
	int argc = 0;
	char** argv = NULL;
	glutInit(&argc,argv);
	
	return 0;
}


int 
GLUTGUIWrapper::createMainWindow(int width, int height) const
{
	glutInitWindowSize(width, height);
	m_windowIdentifier = glutCreateWindow("MainWindow");
	return 0;
}

int 
GLUTGUIWrapper::displayMode(windowsDisplayMode options) const
{
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	return 0;
}

void
GLUTGUIWrapper::startLoop() const
{
	glutDisplayFunc(displayFunc);
	glutReshapeFunc(reshapeFunc);
	if(m_windowIdentifier > 0)
		glutMainLoop();
	stopLoop();
}

void
GLUTGUIWrapper::stopLoop() const
{
	theGullEngine->stop();
}

void 
GLUTGUIWrapper::refresh() const
{
	glutSwapBuffers();
	glutPostRedisplay();
}

